package com.greystripe.sdk;

import android.content.Context;
import android.graphics.Canvas;
import android.view.ViewGroup.LayoutParams;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import java.util.LinkedList;
import java.util.Timer;

final class aa extends WebView
{
  private static boolean d = true;
  private final int a = 30000;
  private final int b = 300;
  private String c;
  private ag e;
  private Timer f;
  private Timer g;
  private boolean h = false;
  private LinkedList i = new LinkedList();
  private boolean j = true;
  private boolean k;
  private WebChromeClient l;

  protected aa(Context paramContext, ag paramag)
  {
    super(paramContext);
    this.e = paramag;
    setBackgroundColor(0);
    this.l = new WebChromeClient();
    setWebChromeClient(this.l);
    setWebViewClient(new af(this, (byte)0));
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    setScrollContainer(false);
    setEnabled(true);
    setClickable(true);
    setPadding(0, 0, 0, 0);
    setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
    WebSettings localWebSettings = getSettings();
    localWebSettings.setLightTouchEnabled(true);
    localWebSettings.setJavaScriptEnabled(true);
    localWebSettings.setLoadsImagesAutomatically(true);
    localWebSettings.setJavaScriptCanOpenWindowsAutomatically(false);
    localWebSettings.setSupportMultipleWindows(false);
    localWebSettings.setPluginsEnabled(true);
    localWebSettings.setCacheMode(1);
    localWebSettings.setSupportZoom(false);
    localWebSettings.setDatabaseEnabled(true);
    localWebSettings.setDomStorageEnabled(true);
    if (d)
    {
      bd.b("First webview loaded.", new Object[0]);
      CookieSyncManager.createInstance(paramContext);
      CookieManager.getInstance().removeExpiredCookie();
      CookieManager localCookieManager = CookieManager.getInstance();
      String str = bj.c().substring(1 + (bj.c().indexOf("http://") + "http://".length()));
      localCookieManager.setCookie(str.substring(str.indexOf('/')), "GS_Session=0");
      CookieSyncManager.getInstance().sync();
      d = false;
    }
    addJavascriptInterface(bj.a(), "Preferences");
    addJavascriptInterface(bd.a(), "SdkLog");
    addJavascriptInterface(new ah(this, (byte)0), "ResponseStatus");
  }

  private void b()
  {
    try
    {
      this.h = false;
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  private void c()
  {
    try
    {
      for (String str = (String)this.i.poll(); str != null; str = (String)this.i.poll())
        loadUrl(str);
      this.h = true;
      return;
    }
    finally
    {
    }
  }

  protected final void a()
  {
    if (this.g != null)
    {
      bd.b("CANCELLING LOAD TIMER", new Object[0]);
      this.g.cancel();
      this.g = null;
    }
  }

  public final void a(int paramInt1, int paramInt2)
  {
    bd.b("onResponseStatusKnown(" + paramInt1 + ")", new Object[0]);
    switch (paramInt1)
    {
    default:
      bd.b("Ad Response Status: Server Error", new Object[0]);
      this.e.a(GSAdErrorCode.SERVER_ERROR);
    case -1:
    case 0:
    case 1:
    case 2:
    }
    while (true)
    {
      if (paramInt2 > 0)
      {
        bd.b("Starting to throttle with time " + paramInt2, new Object[0]);
        this.e.c();
        int m = paramInt2 * 1000;
        this.f = new Timer();
        this.f.schedule(new ac(this), m);
      }
      return;
      bd.b("Ad Response Status: No Status Code", new Object[0]);
      this.e.a(GSAdErrorCode.SERVER_ERROR);
      paramInt2 = 300;
      continue;
      bd.b("Ad Response Status: Success", new Object[0]);
      this.e.a();
      continue;
      bd.b("Ad Response Status: Blank Ad", new Object[0]);
      this.e.a(GSAdErrorCode.NO_AD);
      continue;
      bd.b("Ad Response Status: Invalid Application Identifier", new Object[0]);
      this.e.a(GSAdErrorCode.INVALID_APPLICATION_IDENTIFIER);
    }
  }

  public final void a(String paramString)
  {
    long l1 = bj.e();
    bd.b("STARTING LOAD TIMER with time " + l1, new Object[0]);
    this.k = false;
    this.g = new Timer();
    this.g.schedule(new ad(this), l1);
    if (paramString.contains("?"));
    for (String str = paramString.replaceFirst("\\?", "?z=" + System.currentTimeMillis() + '&'); ; str = paramString + "?z=" + System.currentTimeMillis())
    {
      this.c = str;
      loadUrl(str);
      this.j = true;
      return;
    }
  }

  public final void b(String paramString)
  {
    try
    {
      String str = String.format("javascript:try{%s}catch(e){}", new Object[] { paramString });
      if (this.h)
        loadUrl(str);
      while (true)
      {
        return;
        this.i.add(str);
      }
    }
    finally
    {
    }
  }

  public final void loadUrl(String paramString)
  {
    if (bd.b())
      bd.b("loadUrl(\"" + paramString + "\")", new Object[0]);
    bm.a(new ab(this, paramString));
  }

  public final void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    if (this.j)
    {
      this.j = false;
      bd.b("onDraw() called in webview: " + toString(), new Object[0]);
      this.e.b();
    }
  }

  @Deprecated
  public final boolean post(Runnable paramRunnable)
  {
    return super.post(paramRunnable);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.greystripe.sdk.aa
 * JD-Core Version:    0.6.2
 */